package com.zr.demo;

import com.zr.corporate.pojo.CorporateFactoryAddVo;
import com.zr.corporate.pojo.CorporateVo;
import com.zr.demo.mapper.DemoMapper;
import com.zr.demo.pojo.DemoPlant;
import com.zr.demo.pojo.PlantAddVoList;
import com.zr.util.ResultVo;
import com.zr.util.ResultVoBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.BindResult;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * Created by Hasee on 2019/9/25.
 */
@RestController
public class DemoController {
    @Autowired
    private DemoMapper demoMapper;
    /**
     * 批量查询
     * @return
     */
    @PostMapping("queryList")
    public ResultVo queryList(@RequestBody List<Integer> idList){
        List<CorporateVo> corporateVoList = demoMapper.queryPlantByIdList(idList);
        return ResultVoBuilder.success(corporateVoList);
    }
    @PostMapping("queryList2")
    public ResultVo queryList2(@RequestBody DemoPlant demoPlant){
        List<CorporateVo> corporateVoList = demoMapper.queryList(demoPlant);
        return ResultVoBuilder.success(corporateVoList);
    }

    @PostMapping("addList")
    public ResultVo addList(@RequestBody @Valid CorporateFactoryAddVo corporateFactoryAddVo, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            return ResultVoBuilder.error("500",bindingResult.getFieldError().getDefaultMessage());
        }
//        int add = demoMapper.addList(plantVoList);
        return ResultVoBuilder.success();
    }
    @PostMapping("updateList")
    public ResultVo updateList(@RequestBody List<CorporateFactoryAddVo> corporateFactoryAddVoList){
        int add = demoMapper.updateList(corporateFactoryAddVoList);
        return ResultVoBuilder.success();
    }

}
